package edu.java.homework.hw01;

public class TransliterateModifiedCeco {

    public static final String TEST = "test";

    /**
     * @param args
     */
    public static String transliterateToCyrilic(String inputString) {
	// StringBuilder tmpString= new StringBuilder(inputString);
	if (inputString == null) {
	    throw new IllegalArgumentException(
		    "Incorrect input argument - inputString: null");
	}

	StringBuilder resString = new StringBuilder();
	for (int i = 0; i < inputString.length(); i++) {
	    char tmpChar = inputString.charAt(i);
	    switch (tmpChar) {
	    case 'а':
		resString.append('a');
		break;
	    case 'б':
		resString.append('b');
		break;
	    case 'в':
		resString.append('v');
		break;
	    case 'г':
		resString.append('g');
		break;
	    case 'д':
		resString.append('d');
		break;
	    case 'е':
		resString.append('e');
		break;
	    case 'ж':
		resString.append('j');
		break;
	    case 'з':
		resString.append('z');
		break;
	    case 'и':
		resString.append('i');
		break;
	    case 'й':
		resString.append('i');
		break;
	    case 'к':
		resString.append('k');
		break;
	    case 'л':
		resString.append('l');
		break;
	    case 'м':
		resString.append('m');
		break;
	    case 'н':
		resString.append('n');
		break;
	    case 'о':
		resString.append('o');
		break;
	    case 'п':
		resString.append('p');
		break;
	    case 'р':
		resString.append('r');
		break;
	    case 'с':
		resString.append('s');
		break;
	    case 'т':
		resString.append('t');
		break;
	    case 'у':
		resString.append('u');
		break;
	    case 'ф':
		resString.append('f');
		break;
	    case 'х':
		resString.append('h');
		break;
	    case 'ц':
		resString.append("ts");
		break;
	    case 'ч':
		resString.append("ch");
		break;
	    case 'ш':
		resString.append("sh");
		break;
	    case 'щ':
		resString.append("sht");
		break;
	    case 'ъ':
		resString.append('a');
		break;
	    // case 'ы':
	    // resString.append("yo");
	    // break;
	    case 'ь':
		resString.append("yo");
		break;
	    case 'ю':
		resString.append("yu");
		break;
	    case 'я':
		resString.append("ya");
		break;

	    case 'А':
		resString.append('A');
		break;
	    case 'Б':
		resString.append('B');
		break;
	    case 'В':
		resString.append('V');
		break;
	    case 'Г':
		resString.append('G');
		break;
	    case 'Д':
		resString.append('D');
		break;
	    case 'Е':
		resString.append('E');
		break;
	    case 'Ж':
		resString.append('J');
		break;
	    case 'З':
		resString.append('Z');
		break;
	    case 'И':
		resString.append('I');
		break;
	    case 'Й':
		resString.append('I');
		break;
	    case 'К':
		resString.append('K');
		break;
	    case 'Л':
		resString.append('L');
		break;
	    case 'М':
		resString.append('M');
		break;
	    case 'Н':
		resString.append('N');
		break;
	    case 'О':
		resString.append('O');
		break;
	    case 'П':
		resString.append('P');
		break;
	    case 'Р':
		resString.append('R');
		break;
	    case 'С':
		resString.append('S');
		break;
	    case 'Т':
		resString.append('T');
		break;
	    case 'У':
		resString.append('U');
		break;
	    case 'Ф':
		resString.append('F');
		break;
	    case 'Х':
		resString.append('H');
		break;
	    case 'Ц':
		resString.append("Ts");
		break;
	    case 'Ч':
		resString.append("Ch");
		break;
	    case 'Ш':
		resString.append("Sh");
		break;
	    case 'Щ':
		resString.append("Sht");
		break;
	    case 'Ъ':
		resString.append('A');
		break;
	    // case 'Ы':
	    // resString.append("Yo");
	    // break;
	    case 'Ь':
		resString.append("Yo");
		break;
	    case 'Ю':
		resString.append("Yu");
		break;
	    case 'Я':
		resString.append("Ya");
		break;
	    default:
		resString.append(tmpChar);
		// System.out.println("Error");
	    }
	}
	return resString.toString();

    }

    /**
     * 
     * @param inputString
     * @return resString
     */
    public static String transliterateToCyrillicWithoutSwitchCase(
	    String inputString) {
	// StringBuilder tmpString = new StringBuilder(inputString);

	if (inputString == null) {
	    throw new IllegalArgumentException(
		    "Invalid input argument - inputString: null");
	}
	StringBuilder resString = new StringBuilder();
	for (int i = 0; i < inputString.length(); i++) {
	    char tmpChar = inputString.charAt(i);

	    if (tmpChar == 'а') {
		resString.append('a');
	    } else if (tmpChar == 'б')
		resString.append('b');
	    else if (tmpChar == 'в')
		resString.append('v');
	    else if (tmpChar == 'г')
		resString.append('g');
	    else if (tmpChar == 'д')
		resString.append('d');
	    else if (tmpChar == 'е')
		resString.append('e');
	    else if (tmpChar == 'ж')
		resString.append('j');
	    else if (tmpChar == 'з')
		resString.append('z');
	    else if (tmpChar == 'и')
		resString.append('i');
	    else if (tmpChar == 'й')
		resString.append('i');
	    else if (tmpChar == 'к')
		resString.append('k');
	    else if (tmpChar == 'л')
		resString.append('l');
	    else if (tmpChar == 'м')
		resString.append('m');
	    else if (tmpChar == 'н')
		resString.append('n');
	    else if (tmpChar == 'о')
		resString.append('o');
	    else if (tmpChar == 'п')
		resString.append('p');
	    else if (tmpChar == 'р')
		resString.append('r');
	    else if (tmpChar == 'с')
		resString.append('s');
	    else if (tmpChar == 'т')
		resString.append('t');
	    else if (tmpChar == 'у')
		resString.append('u');
	    else if (tmpChar == 'ф')
		resString.append('f');
	    else if (tmpChar == 'х')
		resString.append('х');
	    else if (tmpChar == 'ц')
		resString.append("ts");
	    else if (tmpChar == 'ч')
		resString.append("ch");
	    else if (tmpChar == 'ш')
		resString.append("sh");
	    else if (tmpChar == 'щ')
		resString.append("sht");
	    else if (tmpChar == 'ъ')
		resString.append('a');
	    // else if(tmpChar == 'ы')
	    // resString.append("yo");
	    else if (tmpChar == 'ь')
		resString.append("yo");
	    else if (tmpChar == 'ю')
		resString.append("yu");
	    else if (tmpChar == 'я')
		resString.append("ya");

	    else if (tmpChar == 'А')
		resString.append('A');
	    else if (tmpChar == 'Б')
		resString.append('B');
	    else if (tmpChar == 'В')
		resString.append('V');
	    else if (tmpChar == 'Г')
		resString.append('G');
	    else if (tmpChar == 'Д')
		resString.append('D');
	    else if (tmpChar == 'Е')
		resString.append('E');
	    else if (tmpChar == 'Ж')
		resString.append('J');
	    else if (tmpChar == 'З')
		resString.append('Z');
	    else if (tmpChar == 'И')
		resString.append('I');
	    else if (tmpChar == 'Й')
		resString.append('I');
	    else if (tmpChar == 'К')
		resString.append('K');
	    else if (tmpChar == 'Л')
		resString.append('L');
	    else if (tmpChar == 'М')
		resString.append('M');
	    else if (tmpChar == 'Н')
		resString.append('N');
	    else if (tmpChar == 'О')
		resString.append('O');
	    else if (tmpChar == 'П')
		resString.append('P');
	    else if (tmpChar == 'Р')
		resString.append('R');
	    else if (tmpChar == 'С')
		resString.append('S');
	    else if (tmpChar == 'Т')
		resString.append('T');
	    else if (tmpChar == 'У')
		resString.append('U');
	    else if (tmpChar == 'Ф')
		resString.append('F');
	    else if (tmpChar == 'Х')
		resString.append('H');
	    else if (tmpChar == 'Ц')
		resString.append("Ts");
	    else if (tmpChar == 'Ч')
		resString.append("Ch");
	    else if (tmpChar == 'Ш')
		resString.append("Sh");
	    else if (tmpChar == 'Щ')
		resString.append("Sht");
	    else if (tmpChar == 'Ъ')
		resString.append('A');
	    // else if(tmpChar == 'Ы')
	    // resString.append("Yo");
	    else if (tmpChar == 'Ь')
		resString.append("Yo");
	    else if (tmpChar == 'Ю')
		resString.append("Yu");
	    else if (tmpChar == 'Я') {
		resString.append("Ya");
	    } else {
		resString.append(tmpChar);
	    }
	}
	return resString.toString();

    }

    public static String toUpperCase(String inputString) {
	StringBuilder resString = new StringBuilder();
	if (inputString == null) {
	    throw new IllegalArgumentException(
		    "Invalid input argument - inputString: null");
	}

	int dividingInterval = 'a' - 'A'; // the more optimal solution
	// int dividingInterval = "a".compareTo("A");
	for (int iter = 0; iter < inputString.length(); iter++) {
	    char tempChar = inputString.charAt(iter);
	    if (tempChar < 'A' || (tempChar > 'Z' && tempChar < 'a')
		    || tempChar > 'z') {
		throw new IllegalArgumentException(
			"Invalid input argument: inputString has symbol which is not from English alphabet");
	    }
	    if (tempChar >= 'a' && tempChar <= 'z') {
		tempChar = (char) ((int) tempChar - dividingInterval);
		// resString.append(tempChar);
	    }
	    // else {
	    resString.append(tempChar);
	    // }
	}

	// System.out.println("a: " + (int) 'a');
	// System.out.println("z: " + (int) 'z');
	// System.out.println("A: " + (int) 'A');
	// System.out.println("Z: " + (int) 'Z');

	return resString.toString();

    }

    public static String toUpperCaseWithClassCharacter(String inputString) {
	if (inputString == null) {
	    throw new IllegalArgumentException(
		    "Illegal input string - inputString: null");
	}
	StringBuilder resultString = new StringBuilder(inputString.length());
	int dividingInterval = "a".compareTo("A");
	for (int iter = 0; iter < inputString.length(); iter++) {
	    char tempChar = inputString.charAt(iter);
	    if (tempChar < 'A' || (tempChar > 'Z' && tempChar < 'a')
		    || tempChar > 'z') {
		throw new IllegalArgumentException(
			"Invalid input argument: inputString has symbol which is not from English alphabet");
	    } else if (Character.isLowerCase(tempChar)) {
		// the upper-case character could be obtained in the following
		// way too:
		tempChar = Character.toUpperCase(tempChar);
		resultString.append((char) ((int) tempChar - dividingInterval));
	    } else {
		resultString.append(tempChar);
	    }
	}
	return resultString.toString();

    }

    /**
     * Verifies whether the <code>inputString</code> is equal to the constant
     * {@link TEST}.
     * 
     * NOTE: the method {@link String#equals(Object)} must be used.
     * 
     * @param inputString
     * @return
     */
    public static boolean equalsToConstant(String inputString) {

	if (inputString == null) {
	    throw new IllegalArgumentException(
		    "Invalid input argument - inputString: null");
	}
	// return inputString.equals(TEST); // WRONG
	return TEST.equals(inputString);
    }

    public static boolean equalsToConstantWithCompareTo(String inputString) {

	if (inputString == null) {
	    throw new IllegalArgumentException(
		    "Invalid input argument - inputString: null");
	}
	// return ((inputString.compareTo(TEST) == 0) ? true : false);
	int result = TEST.compareTo(inputString);
	return result == 0;
	// return (TEST.compareTo(inputString) == 0);
    }

    /**
     * 
     * @param args
     */
    public static void main(String[] args) {

	// String getString = null;
	// String getString = "Рачо реже, риба melon."
	// String getString =
	// "Уважаеми, Mr.James! Царeвицата се \"вари\" в salted water!! на бавен огън :) ";
	// String getString="Цамlzбю:";
	// String resString1 = transliterateToCyrilic(getString);
	// System.out.println(getString);
	// System.out.println();
	// System.out.println("resString1:  " + resString1);
	//
	// String resString2 =
	// transliterateToCyrillicWithoutSwitchCase(getString);
	// System.out.println(getString);
	// System.out.println();
	// System.out.println("resString2:  " + resString2);

	// ------------------------------------------- NEW PART
	// ------------------------------
	// ---------------------------- PART ONE------ toUpperCase
	// uSeDFull --> USEDFULL
	// character
	// Hello --> HELLO
	// String inputString1="character";
	// String resultString = toUpperCase(inputString1);
	// System.out.println(inputString1);
	// System.out.println(resultString);

	// ---------------------------- PART TWO
	// String inputString2=null;
	// String inputString3= new String();
	// System.out.println("inputString2: " + inputString2);
	// System.out.println("inputString3: " + inputString3);

	// ---------------------------- PART THREE
	// String inputString2="test1";
	// System.out.println("inputString2: " + inputString2);
	//	
	//	
	//	
	// System.out.println("inputString2==TEST ?  " +
	// equalsToConstant(inputString2));
	// System.out.println("inputString2==TEST ?  " +
	// equalsToConstantWithCompareTo(inputString2));

	// ---------------------------- PART FOUR
	// String str1="papak";
	//	
	// String str2="papak";
	// String str3="rapak"; // this.charAt(1)-anotherString.charAt(1)
	// String str4="mapak"; // this.charAt(1)-anotherString.charAt(1)
	//	
	// String str5="papaka"; // this.length()-anotherString.length() = -1
	// String str6="papa"; // this.length()-anotherString.length() = 1
	// System.out.println("str1 < str2 : " + str1.compareTo(str2));
	// System.out.println("str1 < str3 : " + str1.compareTo(str3));
	// System.out.println("str1 < str4 : " + str1.compareTo(str4));
	// System.out.println("str1 < str5 : " + str1.compareTo(str5));
	// System.out.println("str1 < str6 : " + str1.compareTo(str6));

	// ---------------------------- PART FIVE
	// String str1="papak";
	//	
	// String str2="papak";
	// String str3="rapak"; // this.charAt(1)-anotherString.charAt(1)
	// String str4="mapak"; // this.charAt(1)-anotherString.charAt(1)
	//	
	// String str5="papaka"; // this.length()-anotherString.length() = -1
	// String str6="papa"; // this.length()-anotherString.length() = 1
	//	
	// String str7="paPaK";
	// String str8="PAPAK"; // this.charAt(1)-anotherString.charAt(1)
	// String str9="PapAK";
	//	
	//	
	// System.out.println("str1 < str2 : " +
	// str1.compareToIgnoreCase(str2));
	// System.out.println("str1 < str3 : " +
	// str1.compareToIgnoreCase(str3));
	// System.out.println("str1 < str4 : " +
	// str1.compareToIgnoreCase(str4));
	// System.out.println("str1 < str5 : " +
	// str1.compareToIgnoreCase(str5));
	// System.out.println("str1 < str6 : " +
	// str1.compareToIgnoreCase(str6));
	// System.out.println("str1 < str7 : " +
	// str1.compareToIgnoreCase(str7));
	// System.out.println("str1 < str8 : " +
	// str1.compareToIgnoreCase(str8));
	// System.out.println("str1 < str9 : " +
	// str1.compareToIgnoreCase(str9));

	// ---------------------------- PART SIX
	// String bla="test";
	// String bla2=TEST;
	// bla=new String("test");
	// System.out.println(bla==TEST);
	// System.out.println(bla2==TEST);

	// ---------------------------- PART SEVEN

	// uSeDFull --> USEDFULL
	// character
	// Hello --> HELLO
	// character --> CHARACTER
	// Hell!o --> error
	// Цatsa --> error
	String inputString1 = "Hello";
	String resultString = toUpperCaseWithClassCharacter(inputString1);
	System.out.println(inputString1);
	System.out.println(resultString);

    }

    /**
     * 
     */
    public static void getUTF8Code() {
	char frstSmallLetter = 'а';
	char lstSmallLetter = 'я';

	char frstBigLetter = 'А';
	char lstBigLetter = 'Я';

	System.out.println("First Small BG Letter: " + (int) frstSmallLetter);
	System.out.println("Last Small BG Letter: " + (int) lstSmallLetter);
	System.out.println("First Big BG Letter: " + (int) frstBigLetter);
	System.out.println("Last Big BG Letter: " + (int) lstBigLetter);

	char chr;
	for (chr = 'а'; chr <= 'я'; chr++) {
	    System.out.print(chr);
	}
	System.out.println();

	for (chr = 'А'; chr <= 'Я'; chr++) {
	    System.out.print(chr);
	}

    }
}
